<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>Document</title>
	<!-- <link rel="stylesheet" href="text.css" /> -->
	<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.6/ace.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.6/ext-language_tools.js" type="text/javascript"
		charset="utf-8"></script>
	<!-- 引入jquery CDN -->
	<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
	<style>
		.all {
			width: 800px;
			box-shadow: -10px 10px 25px rgba(210, 210, 210, 0.9);
			margin: auto;
			margin-top: 5%;
			display: flex;
			border-radius: 35px;
			background-color: #ffffff;
			height: 550px;
		}

		.log {
			width: 50%;
			margin: auto;
		}

		.reg {
			width: 50%;
			height: 100%;
			margin: auto;
			background-color: #20b2aa;
			border-radius: 35px;
			color: #ffffff;
		}

		.reg_1 {
			text-align: center;
			margin: auto;
			margin-top: 50%;
		}

		.reg_1 h2 {
			font-weight: 700;
		}

		.reg_1 p {
			margin: 15px 0px 25px 0px;
		}

		.sig {
			width: 70px;
			height: 30px;
			border-radius: 12px;
			background-color: #20b2aa;
			border-color: #fff;
			color: #ffffff;
		}

		#tiao {
			padding: 0em 0;
		}

		.reg_1 a {
			color: #ffffff;
		}

		h3 {
			font-size: 3em;
			color: black;
			padding-bottom: 1em;
			margin: 0;
			text-align: center;
			font-family: "Marvel-Regular";
		}

		.input {
			margin: 10px 50px;
			width: 300px;
			height: 70px;
		}

		span {
			color: #999;
			font-size: 0.85em;
			padding-bottom: 0.2em;
			display: block;
			text-transform: uppercase;
			margin-bottom: 4px;
		}

		.input-text {
			border: 1px solid #555;
			outline-color: #fd9f3e;
			width: 90%;
			font-size: 1em;
			padding: 0.5em;
			line-height: inherit;
		}

		.register-top-grid {
			color: black;
			padding-bottom: 1em;
			margin: 0;
			font-family: "Marvel-Regular";
			margin: 10px 0;
		}

		.text-center {
			text-align: center;
		}

		.tijiao {
			color: rgb(255, 253, 253);
			width: 80px;
			height: 35px;
			background-color: rgb(241, 52, 10);
			border: none;
		}
	</style>
	<script>

		//document.domain = '43.138.112.14';
		

		// function loadXMLDoc() {
		// 	var xmlhttp;
		// 	if (window.XMLHttpRequest) {
		// 		// IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		// 		xmlhttp = new XMLHttpRequest();
		// 	}
		// 	else {
		// 		// IE6, IE5 浏览器执行代码
		// 		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		// 	}
		// 	xmlhttp.onreadystatechange = function () {
		// 		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		// 			document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
		// 		}
		// 	}
		// 	xmlhttp.open("POST", "login_judge", true);
		// 	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		// 	xmlhttp.send("username= &password=");
		// }\






	</script>
</head>



<body>
	<div class="all">
		<div class="log">
			<div class="register">
				<form>
					<div class="register-top-grid">
						<h3>用户登录</h3>
						<div class="input">
							<span>用户名 <label style="color: red">* </label></span>
							<input type="text" id="username" v-model="name" placeholder="请输入用户名" class="input-text" />
						</div>
						<div class="input">
							<span>密码 <label style="color: red">*</label></span>
							<input type="password" id="password" v-model="password" placeholder="请输入密码"
								class="input-text" />
						</div>
					</div>
					<div class="text-center">
						<button class="tijiao" onclick="submit1()">登录</button>
					</div>
				</form>
			</div>
		</div>
		<div class="reg">
			<div class="reg_1">
				<h2>没有账号？</h2>
				<p>立即注册加入我们吧，和我们一起开启旅程吧</p>
				<a href="/register">
					<button type="primary" class="sig">注册</button>
				</a>
			</div>
		</div>
	</div>


	<script>

		
		function setCookie(cname, passwd, exdays) {
			var d = new Date();
			d.setTime(d.getTime() + (exdays * 60 * 1000));
			var expires = "expires=" + d.toGMTString();

			document.cookie = cname + "=" + passwd + ";" + expires + "domain=http://43.138.112.14";

		}
		function getCookieUsr(cname) {
			var x = document.cookie;
			if(x.match(cname) == cname)
			{
				alert("u1: " + cname);
				return cname;
			}
			return "";
		}
		// u2: ername=12;
		// username=12; 12=12; 13=13
		function getCookiePasswd(cname, passwd) {
			var x = document.cookie;
			var t = cname + "=";
			var a = x.toString().indexOf(t);
			var i = a + t.length;
			var j = i+passwd.length;
			var b = x.substring(i, j);
			alert("u2: " + b + " " + i + " " + j);
			if(cname == b)
			{
				return b;
			}
			return "";
		}
		function checkCookie(username, password) {
			var user = getCookieUsr(username);
			var passwd = getCookiePasswd(username, password);
			
			if (user == "") {
				// 没有该用户，需要注册
				var x = document.cookie;
				//setCookie(username, password, 1);
				window.location.href = "http://43.138.112.14:8080/register";
				alert("没有该用户，需要注册 : " + username + " " + + password + " " + x);

				
			}
			else {
				if (user == passwd) {
					// 登录成功
					setCookie(username, password, 100);
					alert("欢迎 " + user + " 再次访问");
				}
				else {
					// 登录失败，密码错误
					//window.location.href = "http://43.138.112.14:8080/login";
					alert("密码错误1 " + user + " " + username);

				}
			}

		}


		function submit1() {
			
			var username = document.getElementById("username").value;
			var password = document.getElementById("password").value;
			checkCookie(username, password);
			alert("点击成功");
		}

		// function setCookie(cname, cvalue, exdays) {
		// 	var d = new Date();
		// 	d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
		// 	var expires = "expires=" + d.toGMTString();
		// 	document.cookie = "usernam2112e=" + cname + ";"+ expires;
		// }
		// function getCookie(cname) {
		// 	var name = cname + "=";
		// 	var ca = document.cookie.split(';');
		// 	for (var i = 0; i < ca.length; i++) {
		// 		var c = ca[i].trim();
		// 		if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); }
		// 	}
		// 	return "";
		// }
		// function checkCookie() {
		// 	var user = getCookie("username");
		// 	if (user != "") {
		// 		alert("欢迎 " + user + " 再次访问");
		// 	}
		// 	else {
		// 		user = prompt("请输入你的名字:", "");
		// 		if (user != "" && user != null) {
		// 			setCookie("username", user, 30);
		// 		}
		// 	}
		// }
	</script>
</body>

</html>